<!--
 * @Description: 裁切记录
 * 
 * @Author: Edan<Edan>
 * @Date: 2024-08-6 09:10:19
 * @FilePath: /yuxiuproweb/src/views/qb/cutRecode/index.vue
-->
<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
    >
      <el-form-item label="客户" prop="clientName">
        <el-input
          v-model="queryParams.clientName"
          placeholder="请输入客户"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="型号" prop="modelNumber">
        <el-input
          v-model="queryParams.modelNumber"
          placeholder="请输入型号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="备注" prop="remarks">
        <el-input
          v-model="queryParams.remarks"
          placeholder="请输入备注"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="裁切日期" prop="cutTimeObj">
        <el-date-picker
          align="center"
          style="width: 240px"
          v-model="cutTimeObj"
          type="daterange"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          value-format="yyyy-MM-dd"
          format="yyyy-MM-dd"
          @change="handleQuery"
        >
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>
	
    <el-row :gutter="10" class="mb8">
		<el-col :span="1.5">
		  <el-button
		    type="warning"
		    plain
		    icon="el-icon-download"
		    size="mini"
		    @click="handleExport"
		    v-hasPermi="['qb:cutRecode:export']"
		  >导出</el-button>
		</el-col>
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>
    <el-table
      v-loading="loading"
      :data="addressList"
      @selection-change="handleSelectionChange"
      :max-height="maxHeight"
      :row-style="{ height: '20px' }"
      :cell-style="{ padding: '0px', 'font-size': '15px' }"
      border
      size="mini"
    >
      <el-table-column type="selection" width="55" align="center" />
      <template v-for="(i, index) in tableForm.item">
        <el-table-column
          :key="index"
          :prop="i.itemcode"
          :columnKey="i.itemcode"
          :label="i.itemname"
          :align="i.aligntype ? i.aligntype : 'center'"
          :min-width="i.minwidth"
          :width="!!i.width ? i.width : ''"
          :show-overflow-tooltip="i.overflow ? true : false"
          :sortable="i.sortable ? true : false"
          v-if="i.displaymark ? true : false"
        >
          <template slot-scope="scope">
            <div v-if="i.itemcode == 'isDefault'">
              <span v-if="scope.row[i.itemcode] == 1">是</span>
              <span v-else>否</span>
            </div>
            <div v-else-if="i.itemcode == 'technology'">
              <span v-if="scope.row[i.itemcode] == 0">冷胶</span>
              <span v-else-if="scope.row[i.itemcode] == 1">热胶</span>
              <span v-else-if="scope.row[i.itemcode] == 3">先冷后热</span>
              <span v-else>无工艺</span>
            </div>
            <div v-else-if="i.itemcode == 'cuttingDate'">
              {{ scope.row[i.itemcode] | dateFormats }}
            </div>
            <span v-else>{{ scope.row[i.itemcode] }}</span>
          </template>
        </el-table-column>
      </template>
      <el-table-column
        label="操作"
        align="center"
        width="180px"
        class-name="small-padding fixed-width"
        fixed="right"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            >修改</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            style="color: #ff9292"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改高端定制对话框 -->
    <add-view
      v-if="open.show"
      :show.sync="open.show"
      v-bind="open"
      @update="getList"
    ></add-view>
  </div>
</template>

<script>
import { getCutRecodeList, delCutRecodeList } from "@/api/qb/cutRecode";
import AddView from "./mods/add.vue";
import { tableList } from "./mods/tablecolums.js";
import commonMix from "@/utils/mixins/common";
export default {
  name: "cutRecode",
  components: {
    AddView,
  },
  mixins: [commonMix],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 墙布表格数据
      addressList: [],
      // 是否显示弹出层
      open: {
        show: false,
        type: "add",
        data: null,
      },
      cutTimeObj: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 100,
        clientName: null,
        oid: null,
        modelNumber: null,
        batchNumber: null,
        remarks: null,
      },
      //
      tableForm: tableList,
    };
  },
  created() {
    this.getList();
  },
  methods: {
	  handleExport() {
	    this.download(
	      "qb/cuttingRecords/export",
	      {
	        ...this.queryParams,
	      },
	      `client_${new Date().getTime()}.xlsx`
	    );
	  },
    /** 查询高端定制列表 */
    getList() {
      this.loading = true;
      const params = {
        ...this.queryParams,
        startDate: this.cutTimeObj?.[0] || null,
        endDate: this.cutTimeObj?.[1] || null,
      };
      getCutRecodeList(params).then((res) => {
        this.addressList = res.rows;
        this.total = res.total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.cutTimeObj = [];
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      console.log(selection);
      this.ids = selection.map((item) => item.deliveryAddressId);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd(row) {
      const datarow = { ...row } || null;
      this.open = {
        show: true,
        type: "add",
        data: datarow,
      };
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.open = {
        show: true,
        type: "edit",
        data: {
          ...row,
        },
      };
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const projectIds = [row.id] || this.ids;
      this.$modal
        .confirm("该操作不可逆，是否确定删除？")
        .then(function () {
          return delCutRecodeList(projectIds);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
  },
  filters: {
    dateFormats(dataStr) {
      var dt = new Date(dataStr);
      var y = dt.getFullYear();
      // 得到的是0月，所以+1
      var m = (dt.getMonth() + 1).toString().padStart(2, "0");
      // .toString.padStart(最大字符串长度值，"要替补的符号或值")
      var d = dt.getDate().toString().padStart(2, "0");
      // 模板字符串
      return `${y}-${m}-${d}`;
    },
  },
};
</script>
